package controller;


import domain.Userinfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 用户接口类（控制类）
 */

@Controller
public class UserinfoController {
    /**
     * http://localhost:3000/login?username=zhangsan&password=123456      GET
     *
     * 处理登录
     */

    @GetMapping("/login")
    @ResponseBody

    //RequestParam  get? name=张三&id=1
    public  Object login(@RequestParam(value = "username",required=true) String username,
                         @RequestParam(value = "password",required = false,defaultValue = "123456")
                         String password){
        HashMap map=new HashMap();
        if ("admin".equals(username)&&"123456".equals(password)){
            map.put("message","登录成功");
        }else {
            map.put("message","用户名或者密码错误");
        }
        return map;
    }

/**
 * 注册
 * fetch("http://localhost:3000/userinfo/reqister",{
 *     method:"post",
 *     body:JSON.Stringify({
 *         username:"张三"
 *     })
 * })
 */
@GetMapping("reqister")
@ResponseBody
public  Object  reqister  (@RequestBody  Userinfo userinfo){
    System.out.println(userinfo.getUsername());
    HashMap map =  new HashMap();
    map.put ("message",userinfo);
    return  map;

    }


    /**
     *查询某个商品
     */

 @PostMapping("/goods/{id}")
 @ResponseBody
    public  Object queryGoods(@PathVariable("id") String id){
     System .out.println("前端传过来的编号师"+id);
     //TOOD  查询数据库
     ArrayList list =new ArrayList();
     list.add("木瓜多多");
     list.add("木瓜多多");
     list.add("木瓜多多");
     list.add("木瓜多多");
     return  list;

 }
    /**
     * 遍历D盘下所有的文件名字
     * return
     */
    @GetMapping("/list")
    @ResponseBody
    public Object listfile(){
        File file=new File("0\\");
        String [] fileNames = file.list();
        return  fileNames;
    }
}


/**
 * @Get
 */




















/**
 * 注册
 */